import React, { Component } from 'react'
import { withRouter, BrowserRouter as Router, Route } from 'react-router-dom'
import Login from './page/login/login'
import DzMain from './page/main/main'
import NotFountPage from './page/404/404'
import { ToastContainer } from 'react-toastify'
import { getToken } from './utils/tools'

class DzRouter extends Component {
    constructor(props) {
        super(props)
        const token = getToken()
        console.log()
        if (!token) {
            this.props.history.push('/login')
        }
        else if (this.props.history.location.pathname === '/') {
            this.props.history.push('/main/home')
            localStorage.setItem('current-menu', '/main/home');
        }
    }
    state = {}
    render() {
        return (
            <Router>
                <Route path='/login' exact component={Login} />
                <Route path='/main' component={DzMain} />
                <Route path='/404' component={NotFountPage} />
                <ToastContainer></ToastContainer>
            </Router >
        );
    }
}

export default withRouter(DzRouter);
